package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.dto.DimissionInfoDto;
import com.zhangtai.modules.entity.employee.DimissionSettlementEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-09-01 11:37:08
 */
@Mapper
public interface DimissionSettlementDao extends BaseMapper<DimissionSettlementEntity> {

    @Select(
            "<script> SELECT\n" +
                    "\ttds.*,\n" +
                    "\ttei.NAME,\n" +
                    "\ttei.CODE,\n" +
                    "\ttei.oid,\n" +
                    "\ttei.job_id,\n" +
                    "\ttei.jobname,\n" +
                    "\ttei.unit_id,\n" +
                    "\ttei.unitname,\n" +
                    "\ttei.org_id,\n" +
                    "\ttei.orgname,\n" +
                    "\ttei.job_Level_id,\n" +
                    "\ttei.job_level,\n" +
                    "\ttei.job_level_type,\n" +
                    "\ttei.hiredate ,\n" +
                    "\ttei.idcard ,\n" +
                    "\ttei.mobile ,\n" +
                    "\ttdi.dimission_time, \n" +
                    "\ttdi.working_years, \n" +
                    "\ttdi.mode, \n" +
                    "\ttdi.dimission_type, \n" +
                    "\ttdi.associate \n" +
                    "FROM\n" +
                    "\ttb_dimission_settlement tds\n" +
                    "\tLEFT JOIN tb_dimission_info tdi ON tds.dimission_id = tdi.id\n " +
                    "\tLEFT JOIN tb_employee_info tei ON tei.oid = tdi.oid\n " +
                    "  <where> tdi.is_delete = 0 and  tds.is_delete = 0" +
                    "<if test='orgIds!=null and orgIds.size>0'> and tdi.unit_id in " +
                    " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
                    "</if>"+
                    "<if test='orgIds==null or orgIds.size==0'> and tdi.unit_id = null </if>" +
                    "<if test='oid!=null'> and tdi.oid = #{oid} </if>" +
                    "<if test='name!=null'> and tei.name like '%${name}%' </if>" +
                    "<if test='code!=null'> and tei.code like '%${code}%' </if>" +
                    "<if test='hiredateStart!=null'> and tei.hiredate &gt;= #{hiredateStart} </if>" +
                    "<if test='hiredateEnd!=null'> and tei.hiredate &lt;= #{hiredateEnd} </if>" +
                    "<if test='status!=null'> and tds.status = #{status} </if>" +
                    "<if test='processingStatus!=null'> and tds.processing_status = #{processingStatus} </if>" +
                    "</where>  ORDER BY tds.create_time DESC " +
                    //"</where>  ORDER BY tds.create_time DESC ,tds.status asc " +
                    "</script>"
    )
    List<DimissionInfoDto> getDimissionInfoList(
            @Param(value = "orgIds") List<Long> orgIds,
            @Param(value = "oid") String oid,
            @Param(value = "name") String name,
            @Param(value = "code") String code,
            @Param(value = "hiredateStart") String hiredateStart,
            @Param(value = "hiredateEnd") String hiredateEnd,
            @Param(value = "status") Integer status, //审批状态
            @Param(value = "processingStatus") Integer processingStatus, //处理状态
            Page<DimissionInfoDto> page
    );


}
